<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="">
        <p>用户：<input type="text" id="username"></p>
        <p>密码：<input type="text" id="password"></p>
        <button id="btn">登录</button>
    </form>
    <script>
        btn.onclick=function(){
            var username=document.querySelector("#username").value
            var password=document.querySelector("#password").value
            var xhr=new XMLHttpRequest()
            xhr.open("POST","./_07post.php")
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            var data="username="+username+"&password="+password
            xhr.send(data)
            xhr.onreadystatechange=function(){
                if(xhr.readyState===4&&/^2\d{2}/.test(xhr.status)){
                    console.log(123);
                    
                    if(xhr.responseText==="登录成功"){
                        alert("登录成功")
                    }else{
                        alert("登陆失败")
                    }
                }
            }
        }
    </script>
</body>
</html>